package com.github.postsanf.yinian.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.GridView;
import android.widget.TextView;

import com.github.postsanf.yinian.BaseActivity;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.StealPhotosYearAdapter;
import com.github.postsanf.yinian.bean.StealPhotoInfo;
import com.github.postsanf.yinian.bean.StealPhotoInfoList;
import com.github.postsanf.yinian.bean.StealYearString;

import java.util.List;

public class StealPhotosYearActivity extends BaseActivity implements View.OnClickListener {
    private TextView photoyear_title;
    private GridView gridView;
    private String yourUnickname;
    private List<StealPhotoInfo> StealPhotoInfos;
    private int beUserid;
    private String year;
    private int num;
    private StealPhotosYearAdapter stealPhotosDateAdapter;
    public static int total = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stealphotoyear);
//        yourUnickname = getIntent().getStringExtra("yourunickname");
        beUserid = getIntent().getIntExtra("beUserid", 0);
        num = getIntent().getIntExtra("num", 0);
        year = getIntent().getStringExtra("year");
        StealPhotoInfoList stealPhotoInfoList = (StealPhotoInfoList) getIntent().getSerializableExtra("stealPhotoInfoList");
        StealPhotoInfos = stealPhotoInfoList.getStealPhotoInfoList();
        total = 3 - StealPhotoInfos.size();
        initView();
        if (StealEachPhotosActivity.photos.size() == 0) {
            for (int i = 0; i < num; i++) {
                if (!compareInfos(i)) {
                    StealYearString stealYearString = new StealYearString();
                    stealYearString.setUrl("");
                    StealEachPhotosActivity.photos.add(stealYearString);
                }
            }
        }
    }

    private boolean compareInfos(int num) {
        if (StealPhotoInfos != null && StealPhotoInfos.size() > 0) {
            for (int j = 0; j < StealPhotoInfos.size(); j++) {
                StealPhotoInfo stealPhotoInfo = StealPhotoInfos.get(j);
                if (Integer.parseInt(stealPhotoInfo.getPosition()) == num) {
                    StealYearString stealYearString = new StealYearString();
                    stealYearString.setUrl(stealPhotoInfo.getPhoto());
                    StealEachPhotosActivity.photos.add(stealYearString);
                    return true;
                }
            }
        } else {
            return false;
        }
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        stealPhotosDateAdapter.notifyDataSetChanged();
    }

    private void initView() {
        findViewById(R.id.iv_back).setOnClickListener(this);
        photoyear_title = (TextView) findViewById(R.id.photoyear_title);
//        photodate_title.setText(yourUnickname + "的本地图片");
        gridView = (GridView) findViewById(R.id.photoyear_gv);
        stealPhotosDateAdapter = new StealPhotosYearAdapter(StealPhotosYearActivity.this, application, year, beUserid);
        gridView.setAdapter(stealPhotosDateAdapter);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        total = 0;
    }
}
